package com.lzy.cloud.mq.service;

import com.lzy.cloud.mq.config.ConfigMq;
import com.lzy.cloud.mq.remote.PaymentApi;
import com.lzy.cloud.mq.remote.dtos.MsgOrderRefundDto;
import com.lzy.cloud.mq.remote.dtos.PayBackDTO;
import com.lzy.framework.core.utils.DozerUtils;
import lombok.extern.java.Log;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Component;

@Component
@Log
public class PaymentReceiver {

    @Autowired
    PaymentApi paymentApi;

    @RabbitListener(queues = ConfigMq.PAYMENT_QUEUE)
    @RabbitHandler
    @SendTo(ConfigMq.PAYMENT_QUEUE)
    public String receive(PayBackDTO payBackDTO) {
        log.info("payment.processing receive message: 支付回调业务处理接收");
        return DozerUtils.map(paymentApi.notify(payBackDTO).getResult(),String.class);
    }

//    @RabbitListener(queues = ConfigMq.UNSUBSCRIBE_QUEUE)
//    @RabbitHandler
//    @SendTo(ConfigMq.UNSUBSCRIBE_QUEUE)
//    public String receive(MsgOrderRefundDto msgOrderRefundDto) {
//        log.info("unsubscribe receive message: 退订退款业务处理接收");
//        return DozerUtils.map(paymentApi.notify(payBackDTO).getResult(),String.class);
//    }
}
